window.onload=function (){
    axios.get("/user/getLoginUser").then(resp=>{
        var info = resp.data;
        userId=info.userId;
        oldPwd=info.pwd;
    })
}
var userId;
var oldPwd;
function verify(){
    if ($("oldPwd").value==null||$("oldPwd").value==""){
        $("errorSpan").innerHTML="输入不能为空";
        $("errorSpan").style.color="red";
    }else {
        $("errorSpan").innerHTML="";
    }
    if ($("newPwd").value==null||$("newPwd").value==""){
        $("errorSpan1").innerHTML="输入不能为空";
        $("errorSpan1").style.color="red";
    }else {
        $("errorSpan1").innerHTML="";
    } if ($("newsPwd").value==null||$("newsPwd").value==""){
        $("errorSpan2").innerHTML="输入不能为空";
        $("errorSpan2").style.color="red";
    }else {
        $("errorSpan2").innerHTML="";
    }
    if (oldPwd!=$("oldPwd").value){
        $("errorSpan").innerHTML="旧密码输入错误";
        $("errorSpan").style.color="red";
    }
    if ($("newPwd").value!=$("newsPwd").value){
        $("errorSpan2").innerHTML="两次密码输入不同";
        $("errorSpan2").style.color="red";
    }
}

function updatePwd(){
    axios.get("/user/updatePwd",{
        params:{
            userId,
            newPwd:$("newPwd").value,
            oldPwd:$("oldPwd").value
        }
    }).then(resp=>{
        var info = resp.data;

        if (info=="ok"){
            $("errorDiv").style.visibility="visible"
            $("jumpInput").style.visibility="visible"
            $("updateSpan").innerHTML="修改成功"
            $("updateSpan").style.color="green";

        }else {
            $("errorDiv").style.visibility="visible"
            $("exitInput").style.visibility="visible"
            $("updateSpan").innerHTML="修改失败"
            $("updateSpan").style.color="red";
        }
    })
}
function jump(){
    $("jumpInput").style.visibility="hidden";
    top.location.href="../login/login.html";
}
function exit(){
    $("errorDiv").style.visibility="hidden";
    $("exitInput").style.visibility="hidden";
}